﻿<Window x:Class="Dropboxifier.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:validators="clr-namespace:Dropboxifier.Validators"
        Title="{Binding WindowTitle, Mode=OneTime}" Height="330" Width="637"
        MinHeight="330" MinWidth="637"
        Loaded="Window_Loaded" Icon="/Dropboxifier;component/Images/Drop-Box-icon.png" Closing="Window_Closing">
    <Window.Resources>
        <CollectionViewSource x:Key="dropboxifierViewModelLinkedFoldersViewSource" Source="{Binding Path=LinkedFolders}" />        
        <Style TargetType="{x:Type Button}" x:Key="DropboxifyValidator">
            <Setter Property="IsEnabled" Value="False" />
            <Style.Triggers>
                <MultiDataTrigger>
                    <MultiDataTrigger.Conditions>
                        <Condition Binding="{Binding ElementName=txtDropboxFolder, Path=(Validation.HasError)}" Value="False" />
                        <Condition Binding="{Binding ElementName=txtLinkName, Path=(Validation.HasError)}" Value="False" />
                        <Condition Binding="{Binding ElementName=txtLinkSource, Path=(Validation.HasError)}" Value="False" />
                    </MultiDataTrigger.Conditions>
                    <Setter Property="IsEnabled" Value="True" />
                </MultiDataTrigger>
            </Style.Triggers>
        </Style>
        <Style TargetType="{x:Type DataGridRow}" x:Key="LinkedFolderRowStyle">
            <Setter Property="Background" Value="YellowGreen" />
            <Style.Triggers>
                <Trigger Property="Validation.HasError" Value="True">
                    <Setter Property="Background" Value="IndianRed" />
                </Trigger>
            </Style.Triggers>
        </Style>
    </Window.Resources>
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition MinWidth="20" Width="2*"/>
            <ColumnDefinition Width="Auto"/>
            <ColumnDefinition MinWidth="20" Width="3*"/>
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="1*" />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>
        <Border Grid.ColumnSpan="3" Grid.Row="0" BorderBrush="LightSteelBlue" BorderThickness="1" Margin="2" CornerRadius="2">
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto" />
                    <ColumnDefinition Width="1*" />
                    <ColumnDefinition Width="Auto" />
                </Grid.ColumnDefinitions>                
                <Label Grid.Column="0" Content="Dropbox folder:" />
                <TextBox Grid.Column="1" Margin="3" IsEnabled="True" Name="txtDropboxFolder" ToolTip="The Dropbox destination directory. Linking will work with any subdirectory under the main Dropbox directory. It is recommended to use a subdirectory within your main Dropbox folder.">
                    <TextBox.Text>
                        <Binding Path="DropboxFolder" Mode="TwoWay">
                            <Binding.ValidationRules>
                                <ExceptionValidationRule />
                                <validators:FolderValidator ValidatesOnTargetUpdated="true" />
                            </Binding.ValidationRules>
                        </Binding>
                    </TextBox.Text>
                </TextBox>
                <Button Grid.Column="2" Content="..." Margin="3" Width="20" Click="dropboxFolderSelectButton_OnClick" ToolTip="Browse for Dropbox directory..." />
            </Grid>
        </Border>        
        <Border Grid.Column="0" Grid.Row="1" BorderBrush="LightSteelBlue" BorderThickness="1" CornerRadius="2" Margin="2">
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="1*"/>
                </Grid.RowDefinitions>
                <Label Grid.Row="0" Margin="3" Height="Auto" Content="Add New Link" FontWeight="Bold" HorizontalAlignment="Center"/>
                <Grid Grid.Row="1">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto"/>
                        <ColumnDefinition Width="1*"/>
                    </Grid.ColumnDefinitions>
                    <Label Width="50" Margin="3" DockPanel.Dock="Left" Content="Name:" />
                    <TextBox Grid.Column="1" DockPanel.Dock="Right" Margin="3" Name="txtLinkName" ToolTip="Name to give linked item - will also be used as a subdirectory in the Dropbox folder.">
                        <TextBox.Text>
                            <Binding Path="NextLinkName" Mode="TwoWay" UpdateSourceTrigger="PropertyChanged">
                                <Binding.ValidationRules>
                                    <ExceptionValidationRule />
                                    <validators:LinkNameValidator ValidatesOnTargetUpdated="true" />
                                </Binding.ValidationRules>
                            </Binding>
                        </TextBox.Text>
                    </TextBox>
                </Grid>
                <Grid Grid.Row="2">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto"/>
                        <ColumnDefinition Width="1*"/>
                        <ColumnDefinition Width="Auto"/>
                    </Grid.ColumnDefinitions>
                    <Label Margin="3" Grid.Column="0" Width="50" Content="Source:" />
                    <TextBox Grid.Column="1" Margin="3" Name="txtLinkSource" ToolTip="The source directory to link.">
                        <TextBox.Text>
                            <Binding Path="NextLinkSource" Mode="TwoWay" UpdateSourceTrigger="PropertyChanged">
                                <Binding.ValidationRules>
                                    <ExceptionValidationRule />
                                    <validators:FolderValidator ValidatesOnTargetUpdated="true" />
                                </Binding.ValidationRules>
                            </Binding>
                        </TextBox.Text>
                    </TextBox>
                    <Button Grid.Column="2" Margin="3, 5" Content="..." Width="20" Click="sourceDirFolderSelectButton_OnClick" ToolTip="Browse for source directory..." />
                </Grid>
                <Button Grid.Row="3" Margin="3" Content="Dropboxify -->" HorizontalAlignment="Right" VerticalAlignment="Top" Style="{StaticResource DropboxifyValidator}" Click="dropboxifyButton_OnClick" ToolTip="Moves the source directory into Dropbox and creates a symbolic link." />
                <GroupBox Grid.Row="4" Header="Disclaimer" HorizontalAlignment="Center" VerticalAlignment="Top">
                    <TextBlock Width="236" Height="96" TextWrapping="Wrap">
                        This is <Bold>BETA SOFTWARE</Bold>.
                        Make backups of your data before dropboxifying. I take no responsibility for lost data! Remember that any uploaded data can be recovered from your
                        <Hyperlink Click="hyperlink_Clicked">Dropbox Home
                          <Hyperlink.NavigateUri>
                            <![CDATA[https://www.dropbox.com/home]]>
                          </Hyperlink.NavigateUri>
                        </Hyperlink>. 
                        <Hyperlink NavigateUri="http://db.tt/YQjh65g" Click="hyperlink_Clicked">Get Dropbox</Hyperlink>.
                        <Hyperlink NavigateUri="http://dropboxifier.codeplex.com" Click="hyperlink_Clicked">Dropboxifier Home</Hyperlink>.
                    </TextBlock>
                </GroupBox>
            </Grid>
        </Border>

        <GridSplitter Grid.Row="1" Grid.Column="1" Height="Auto" Width="2" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
                      ResizeBehavior="PreviousAndNext" ResizeDirection="Columns" Background="White" />
        
        <Border Grid.Column="2" Grid.Row="1" BorderBrush="LightSteelBlue" BorderThickness="1" CornerRadius="2" Margin="2">
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="1*" />
                    <RowDefinition Height="Auto" />
                </Grid.RowDefinitions>
                <Label Grid.Row="0" HorizontalAlignment="Center" Height="Auto" FontWeight="Bold" Content="Dropboxified Folders" />
                <DataGrid RowStyle="{StaticResource LinkedFolderRowStyle}" Margin="3" Grid.Row="1" AutoGenerateColumns="False" ItemsSource="{Binding Source={StaticResource dropboxifierViewModelLinkedFoldersViewSource}}" Name="linkedFoldersDataGrid" CanUserResizeRows="False" SelectionChanged="linkedFoldersDataGrid_SelectionChanged">
                    <DataGrid.Columns>
                        <DataGridTextColumn IsReadOnly="true" x:Name="linkName" Binding="{Binding Path=LinkName}" Header="Name" Width="Auto" />
                        <DataGridTextColumn IsReadOnly="True" Binding="{Binding Path=SyncedPCsString}" Header="Resolved On" Width="Auto" />
                        <DataGridTextColumn IsReadOnly="True" x:Name="sourceFolderColumn" Binding="{Binding Path=SourceFoldersString}" Header="Source" Width="2*" />
                        <DataGridTextColumn IsReadOnly="True" x:Name="destFolderColumn" Binding="{Binding Path=DestFoldersString}" Header="Destination" Width="2*" />
                    </DataGrid.Columns>
                    <DataGrid.RowValidationRules>
                        <validators:LinkedFolderValidator ValidatesOnTargetUpdated="True" />
                    </DataGrid.RowValidationRules>
                </DataGrid>
                <Button Grid.Row="2" Margin="3" Content="Resolve..." VerticalAlignment="Bottom" HorizontalAlignment="Left" Width="Auto" Name="btnResolve" IsEnabled="False" Click="btnResolve_Click" />
                <CheckBox Content="Delete Dropboxed Folder" Grid.Row="2" Height="Auto" Margin="0,0,136,6" VerticalAlignment="Bottom" HorizontalAlignment="Right" Width="Auto" IsChecked="True" Name="ChkDeleteDropboxedFolder" ToolTip="Check to also delete the linked folder from Dropbox when undropboxifying." />
                <Button Grid.Row="2" Margin="3" Content="Undropboxify Selected" HorizontalAlignment="Right" Click="undropboxifyButton_OnClick" ToolTip="Moves all selected links back to their original locations. Optionally deletes the links from Dropbox." />
            </Grid>
        </Border>
    </Grid>
</Window>
